package com.itheima.stream;

import com.itheima.domain.Student;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Demo06 {

    public static void main(String[] args) {
        Student cai = new Student("坤坤", 26);
        Student huang = new Student("滔滔", 28);
        Student wu = new Student("签签", 26);
        Student lu = new Student("小鹿", 26);
        List<Student> list = List.of(cai, huang, wu, lu);
      /*  Map<String, Integer> map = list.stream().collect(Collectors.toMap(new Function<Student, String>() {
            @Override
            public String apply(Student student) {
                return student.getName();
            }
        }, new Function<Student, Integer>() {
            @Override
            public Integer apply(Student student) {
                return student.getAge();
            }
        }));*/
        Map<String, Integer> map = list.stream().collect(Collectors.toMap(s -> s.getName(), s -> s.getAge()));
        System.out.println(map);
    }
}
